package cn.dapeng.designPatterns.chain.t02;

import java.util.ArrayList;
import java.util.List;

public class ProcessorChain {

    int index;
    private List<Processor> processors = new ArrayList<>();

    public ProcessorChain addProcessor(Processor processor) {
        processors.add(processor);
        return this;
    }

    public boolean doFilter(Product product, ProcessorChain chain) {
        if (index == chain.processors.size()) {
            index = 0;
            return true;
        }
        return processors.get(index++).doFilter(product, chain);
    }
}
